package poo.file;

import java.io.*;

public class Crittografia {

	public static void main(String[] args) throws IOException {

		File f1 = new File("C:\\Users\\Paco\\Desktop\\prova1.txt");
		File f2 = new File("C:\\Users\\Paco\\Desktop\\prova2.txt");
		int i = 0;
		OutputStream desttmp = new FileOutputStream(f2);
		while (i == 50) {
			desttmp.write(3 + i);
			i++;
		}
		desttmp.close();
		String k = "3";
		if (k.equals(0) && k.equals(-1)) {
			System.out.println("Attesa chiave!");
			System.exit(-1);
		}

		int chiave = Integer.parseInt(k);
		InputStream source = new FileInputStream(f1);
		OutputStream dest = new FileOutputStream(f2);
		int dato;
		for (;;) {
			dato = source.read();
			if (dato == -1)
				break;
			dest.write(crittografa(dato, chiave));
		}
		source.close();
		dest.close();
	}

	private static byte crittografa(int dato, int chiave) {
		return (byte) (dato + chiave);
	}

}
